package com.example.ex_menu;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import static com.example.ex_menu.R.styleable.MenuItem;

public class MenuActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        menu.add(0,1,1, "跳转到MenuContext活动");
        menu.add(0,2,2, "跳转到MenuSUB活动");
        menu.add(0,3,3, "跳转到MenuSUB");
        menu.add(0,4,4, "跳转到ActionBarDemo");
        menu.add(0,5,5, R.string.exit);

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(android.view.MenuItem item){
        switch (item.getItemId()){
            case 1:
                Intent intent = new Intent(MenuActivity.this,MenuContext.class);
                startActivity(intent);
                break;
            case 2:
                Intent intent1 = new Intent(MenuActivity.this,MenuSUB.class);
                startActivity(intent1);
                break;
            case 5:
                finish();

        }

        return super.onOptionsItemSelected(item);
    }
}
